<script lang="ts" setup>
import {
  UserOutlined,
  LeftCircleOutlined,
  RightCircleOutlined,
  DownOutlined,
  ArrowRightOutlined,
  FileDoneOutlined,
  DollarOutlined,
  AlipayCircleOutlined,
  EditOutlined,
  SearchOutlined,
} from "@ant-design/icons-vue";
import { reactive, ref, h, onMounted, getCurrentInstance } from "vue";
import { useRouter } from "vue-router";
import { getCityAll } from "@/api/public/index";
import { getPublishList, getBannerList } from "@/api/mutualaid/index";
import Card from "@/components/Card/index.vue";
import axios from "axios";
import { message } from "ant-design-vue";
const current = getCurrentInstance();
const router = useRouter();
const value = ref<string>("全部");
const searchValue = ref<string>("");
const isShowList = ref<boolean>(false);
const isShowConfirm = ref<boolean>(false);
const spinning = ref<boolean>(true);
const userInfo = reactive(
  JSON.parse(window.localStorage.getItem("userInfo") || "{}")
);

// 

let listCard = reactive({
  bannerList: [] as any[],
  list: [] as Item[],
  storey: [] as any[],
});

const isShowNotice = ref<boolean>(localStorage.getItem("isShowNotice") == 'false' ? false : true);

interface DataItem {
  title: string;
}
interface Item {
  id: number;
  name: string;
  logo: string;
  list: any[];
}

const refreshPage = () => {
  window.location.reload();
};
onMounted(() => {
  if (!userInfo.id) {
    router.push({ path: "/login" });
    return message.error({
      content: "请先登录",
    });
  }
  // getCity();
  publishListMethod();
  handleGetBannerList();
});

const handleGetBannerList = async () => {
  const res = await getBannerList();

  if (res.data.code != 0)
    return message.error({
      content: res.data.msg,
    });

  listCard.bannerList = res.data.data;
};

const getCity = async () => {
  const res = await getCityAll();
  // 
};

const publishListMethod = async () => {
  const res = await getPublishList({
    page: 1,
    limit: 8,
  });
  if(res.data.code === 2) {
    return router.push({ path: '/login' })
  }
  if (res.data.code != 0){
  
    return message.error({
      content: res.data.msg,
    });
  }
  

  listCard.list = res.data.data;
  listCard.list.map((item) => {
    listCard.storey.push({
      key: item.id,
      href: `#${item.name}${item.id}`,
      title: item.name,
    });
  });
  spinning.value = false;
};

const onSearch = () => { };

const handleFocus = () => {
  // 
  isShowList.value = true;
};

const handleBlur = () => {
  // 
  isShowList.value = false;
};

const logIn = () => {
  router.push({ path: "/login" });
  // 
};

const myResources = () => {
  router.push({ path: "/myresources" });
};
const publishingResources = () => {
  router.push({ path: "/publishingresources" });
};
const checkAll = (item: { id: any; name: any }) => {
  router.push({
    path: "/AllResources",
    query: { type: item.id, title: item.name },
  });
};
const gotoWithdrawal = () => {
  router.push({ path: "/withdrawal" });
};

const gotoRecharge = () => {
  router.push({ path: "/withdrawal" });
};
const gotoMyPublish = (item: { id: any }) => {
  router.push({ path: "/publishingresources", query: { type: item.id } });
};
const gotoSearch = () => {
  router.push({ path: "/search" });
};

const changeNotice = () => {
  isShowNotice.value = false;
  localStorage.setItem("isShowNotice", "false");
}
function copyToClipboard(text: string) {
  navigator.clipboard.writeText(text).then(() => {
    message.success({
      content: "已复制到剪贴板",
    })
  }).catch(err => {
    message.error({
      content: "分享失败",
    })
  });
}
</script>


<template>
  <a-spin :spinning="spinning">
    <div class="home_page">
      <a-float-button type="default" shape="square" :style="{
        right: '24px',
      }" description="反馈" @click="router.push({ path: '/feedback' })">
        <template #icon>
          <EditOutlined />
        </template>
      </a-float-button>
      <!-- Navbar -->
      <div style="width: 100%">
        <ul class="nav_item_box">
          <li class="li_item" @click="refreshPage">
            <img src="../../assets/logo/logo.png" alt="logo" class="logo" />
          </li>
          <li class="kover_link">
            <span @click="myResources">我的发布</span>
          </li>
          <li class="kover_link li_item">
            <span @click="publishingResources">发布任务</span>
          </li>
          <li class="search_nav kover_link" @click="gotoSearch">
            <SearchOutlined /> 去搜索
          </li>
          <div class="useInfo " @click="router.push({ path: '/personalcenter' })">
            <img :src="'https://hzh.woide.top' + userInfo.avatar" alt="" class="userInfo_avater"
              style="border-radius: 50%" />
          </div>
        </ul>
        <!-- 个人操作 -->
      </div>
      <div style="width:100%; height: 230px">
        <a-carousel class="h-50" arrows>
          <template #prevArrow>
            <div class="custom-slick-arrow" style="left: 10px; z-index: 1">
              <LeftCircleOutlined />
            </div>
          </template>
          <template #nextArrow>
            <div class="custom-slick-arrow" style="right: 10px">
              <right-circle-outlined />
            </div>
          </template>
          <div v-for="item of listCard.bannerList" :key="item.id">
            <img :src="'https://hzh.woide.top' + item.imgUrl" class="banner" />
            <!-- <a-image :src="'https://hzh.woide.top' + item.imgUrl" width="100%" :preview="false" :placeholder="true"  />" -->
          </div>
        </a-carousel>
      </div>

      <div class="resource_list">
        <div style="margin-top: 30px" v-for="item of listCard.list" :key="item.id">
          <div class="d-flex justify-content-between align-items-center">
            <div class="logo_box" :id="item.name + item.id">
              <img :src="'https://hzh.woide.top' + item.logo" :alt="item.name" class="icon_logo" />
              {{ item.name }}
            </div>
            <a-button shape="round" v-if="item.list.length != 0"
              class="d-flex justify-content-between align-items-center btn_hover" @click="checkAll(item)">
              查看全部
              <ArrowRightOutlined style="vertical-align: -50%" />
            </a-button>
          </div>

          <div class="row row_card">
            <Card class="col-sm-3" v-for="childrenItem of item.list" :key="childrenItem.id" v-show="item.list.length != 0"
              :card-info="childrenItem" mobile="0">
            </Card>

            <div v-show="item.list.length == 0" style="text-align: center; padding-bottom: 30px">
              <a-empty description="还没有发布哦~" />
              <a-button type="primary" @click="gotoMyPublish(item)">去发布</a-button>
            </div>
          </div>
        </div>
      </div>

      <div class="anchor_box">
        <a-anchor :affix="false" :items="listCard.storey" :showInkInFixed="true">
        </a-anchor>
      </div>
    </div>
  </a-spin>
  <a-modal v-model:open="isShowNotice" width="80%" :maskClosable="false" :closable="false" centered
    title="推出全新免费互助平台，致力于解决电商平台仅退款问题" ok-text=" 确认 " cancel-text=" 关闭 " @cancel="changeNotice" @ok="changeNotice">
    <h1>公告</h1>
    <p>亲爱的商户们：</p>
    <p>我们了解到，近年来在电商平台购物时，常常会遇到仅退款的问题。为了解决这一困扰，我们推出了全新的免费互助平台，致力与商户互帮互助。</p>

    <h2>重要声明：</h2>
    <p class="important">平台不保障任何服务，也不以盈利为目的。所有服务均由用户自发提供，平台仅作为信息交流和共享的平台。</p>
    <p>感谢大家的支持和关注，我们期待您的加入，一起构建更友好和公平的购物生态！</p>
    <p class="footer">
     
      平台网址：https://huzhu.woide.top/ <span class="copy" @click="copyToClipboard('https://huzhu.woide.top/')">复制</span><br>  <a-popover>
        <template #content>
          <img src="../../assets/wxchart/user.jpg" alt="" style="width: 120px;">
        </template>
        反馈微信：huzhuhui2024
      </a-popover> <span
        class="copy" @click="copyToClipboard('huzhuhui2024')">复制</span>
    </p>
    <p class="footer">互助平台团队<br>2024年7月31日</p>
  </a-modal>
</template>

<style lang="scss" scoped>
.li_item:hover {
  cursor: pointer;
}

a {
  text-decoration: none !important;
}

.anchor_box {
  position: fixed;
  right: 2%;
  top: 50%;

  z-index: 99;
  background-color: #fff;
}

:deep(.ant-anchor-ink) {
  //竖线右移=================================
  position: absolute;
  top: 0;
  left: 181px;
  height: 100%;
}

//默认的小灰色球球=================================
:deep(.ant-anchor-link) {
  right: 0 !important;
  margin: 10px 34px 10px 0;
  padding: 3px 6px;

  &::before {
    position: absolute;
    right: 10px;
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-top: 7px;
    // background: url(https://img.alicdn.com/tfs/TB1z4dwSFXXXXc6XpXXXXXXXXXX-32-32.png);
    background-size: 100%;
    cursor: default;
    content: "";
  }
}

:deep(.ant-anchor-ink-ball) {
  //高亮蓝色角标=================================
  left: 50%;
  z-index: 99;
  width: 22px !important;
  height: 13px !important;
  background: url(https://img.alicdn.com/tfs/TB196gtSpXXXXayXXXXXXXXXXXX-20-13.png) no-repeat 50% !important;
  background-size: 100%;
  border: 0 !important;
  border-radius: 0 !important;
  -webkit-transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  transform: translateX(-50%);
  -webkit-transition: top 0.3s ease-in-out;
  -o-transition: top 0.3s ease-in-out;
  transition: top 0.3s ease-in-out;
}

.row_card {
  @media screen and (min-width: 400px) {
    margin: 0 !important;
  }
}

.btn_hover:hover {
  display: block;
  filter: drop-shadow(0 0 10px #fffdef);
}

.userInfo_avater {
  width: 30px;
  height: 30px;
}

.banner {
  width: 100%;
  height: 100%;
}

.logo {
  max-width: 100px;
  width: 87px;
  // height: 30px;
}

.search_nav {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 20px;
  background-color: #eee;
  padding: 0 20px;
  border-radius: 10px;
}

.logo {
  float: left;
}

.nav_item_box {
  list-style: none;
  display: block;
  overflow: hidden;
  width: 100%;
  padding: 0;
  margin: 1rem 0;
  line-height: 2;

  .useInfo {
    float: right;
    line-height: 44px;
    margin-right: 10px;

    &:hover {
      cursor: pointer;
    }
  }

  .kover_link {
    list-style-type: none;
    float: left;
    padding: 10px 20px;

    @media screen and (min-width: 400px) {
      padding: 6px 12px;
    }

    &:hover {
      cursor: pointer;
    }
  }
}

.card_box {
  cursor: pointer;
  transition: all 0.2s;

  &:hover {
    transform: translateY(-5px);
    box-shadow: 2px 2px 2px #eee;
    // border: 1px solid #1677ff;
  }

  .card_text {
    width: auto;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

:deep(.slick-slide) {
  text-align: center;
  height: 230px;
  line-height: 230px;
  background: #364d79;
  overflow: hidden;

  img {
    width: 100%;
    height: 230px;
  }
}

:deep(.slick-arrow.custom-slick-arrow) {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  transition: ease all 0.3s;
  opacity: 0.3;
  z-index: 1;
}

:deep(.slick-arrow.custom-slick-arrow:before) {
  display: none;
}

:deep(.slick-arrow.custom-slick-arrow:hover) {
  color: #fff;
  opacity: 0.5;
}

:deep(.slick-slide h3) {
  color: #fff;
}

.home_page {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  min-height: 100vh;
  max-height: auto;

  .resource_list {
    margin-top: 20px;

    .logo_box {
      font-size: 20px;
      padding: 0 10px;
      box-sizing: border-box;

      .icon_logo {
        width: 30px;
        height: 30px;
        border-radius: 50%;
        margin-right: 10px;
      }
    }
  }
}

.search_box {
  width: 100%;
  position: relative;
  height: 40px;

  // background-color: antiquewhite;
  .list_proposal {
    position: absolute;
    width: 100%;
    // bottom: -40px;
    padding: 10px 30px;
    top: 40px;
    box-sizing: border-box;
    z-index: 99999;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 1px 6px 6px -1px #c7c7c7;

    .record {
      .title {
        color: #c7c7c7;
        font-size: 12px;
      }

      .record_list {
        max-height: 350px;
        overflow-y: scroll;
      }
    }
  }
}

// 弹框
.container {
  max-width: 600px;
  margin: 20px;
  padding: 20px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

}

h1 {
  color: #333;
  text-align: center;
}

p,
ul {
  color: #555;
  line-height: 1.6;
}

ul {
  padding-left: 20px;
}

.important {
  font-weight: bold;
  color: #e74c3c;
  text-align: center;
}

.footer {
  text-align: center;
  margin-top: 20px;
  color: #777;

  .copy {
    text-decoration: underline;
    color: #1677ff;

    &:hover {
      cursor: pointer;
    }
  }
}</style>